package com.yanqu.road.server.logic.activity.condition.normal;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.args.WineShopRankArgs;
import com.yanqu.road.entity.wineshop.WineShopRankActivityData;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseRankActivityCondition;
import com.yanqu.road.server.manger.cross3.ChannelRankActivityMgr;

import java.math.BigInteger;
import java.util.Map;

public class OnlyEscortAddExpRankCondition extends BaseRankActivityCondition {

    public OnlyEscortAddExpRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.OnlyEscortAddExpRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.OnlyEscortAddExpRank.getValue(), handle);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        long value = 0L;
        if (object instanceof WineShopRankArgs) {
            WineShopRankArgs wineShopRankArgs = (WineShopRankArgs) object;
            for (Map.Entry<Integer, WineShopRankActivityData> entry : wineShopRankArgs.getActivityDataMap().entrySet()) {
                if (activityInfo.getActivityId() == entry.getKey()) {
                    value = entry.getValue().getMoney();
                    entry.getValue().setMoney(0);
                }
            }
        } else {
            value = (long) object;
        }
        setValue(getValue().add(BigInteger.valueOf(value)));
        //如果是跨域冲榜的话
        if (activityInfo.getType() == eActivityType.ChannelRankActivity.getValue()) {
            ChannelRankActivityMgr.userRankChange(activityInfo.getActivityId(), activityConditionInfo.getType(), getValue().longValue(), player.getUserId(),"");
            //这里借用的是区服只计算押镖经验涨幅榜
            ChannelRankActivityMgr.channelRankPartChange(activityInfo.getActivityId(), eGamePlayerEventType.ServerOnlyEscortAddExpRank.getValue(), getValue().longValue(), player.getUserId());
        } else {
            rankChange();
        }

    }
}
